package com.ruoyi.cms.service.impl;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.cms.mapper.CmsSiteInfoMapper;
import com.ruoyi.cms.domain.CmsSiteInfo;
import com.ruoyi.cms.service.ICmsSiteInfoService;

/**
 * 站点信息Service业务层处理
 *
 * @author ruoyi
 * @date 2022-08-30
 */
@Service
public class CmsSiteInfoServiceImpl implements ICmsSiteInfoService {
    @Autowired
    private CmsSiteInfoMapper cmsSiteInfoMapper;

    /**
     * 查询站点信息
     *
     * @param infoId 站点信息主键
     * @return 站点信息
     */
    @Override
    public CmsSiteInfo selectCmsSiteInfoByInfoId(Long infoId) {
        return cmsSiteInfoMapper.selectCmsSiteInfoByInfoId(infoId);
    }

    @Override
    public CmsSiteInfo selectUseCmsSiteInfo() {
        CmsSiteInfo params = new CmsSiteInfo();
        params.setStatus(Constants.SUCCESS);
        PageUtils.startPage(1, 1, "info_id desc");
        List<CmsSiteInfo> infos = cmsSiteInfoMapper.selectCmsSiteInfoList(params);
        if (infos.isEmpty()) {
            throw new RuntimeException("未设置站点信息");
        }
        CmsSiteInfo info = infos.get(0);
        return info;
    }

    /**
     * 查询站点信息列表
     *
     * @param cmsSiteInfo 站点信息
     * @return 站点信息
     */
    @Override
    public List<CmsSiteInfo> selectCmsSiteInfoList(CmsSiteInfo cmsSiteInfo) {
        return cmsSiteInfoMapper.selectCmsSiteInfoList(cmsSiteInfo);
    }

    /**
     * 新增站点信息
     *
     * @param cmsSiteInfo 站点信息
     * @return 结果
     */
    @Override
    public int insertCmsSiteInfo(CmsSiteInfo cmsSiteInfo) {
        cmsSiteInfo.setCreateTime(DateUtils.getNowDate());
        return cmsSiteInfoMapper.insertCmsSiteInfo(cmsSiteInfo);
    }

    /**
     * 修改站点信息
     *
     * @param cmsSiteInfo 站点信息
     * @return 结果
     */
    @Override
    public int updateCmsSiteInfo(CmsSiteInfo cmsSiteInfo) {
        cmsSiteInfo.setUpdateTime(DateUtils.getNowDate());
        return cmsSiteInfoMapper.updateCmsSiteInfo(cmsSiteInfo);
    }

    /**
     * 批量删除站点信息
     *
     * @param infoIds 需要删除的站点信息主键
     * @return 结果
     */
    @Override
    public int deleteCmsSiteInfoByInfoIds(Long[] infoIds) {
        return cmsSiteInfoMapper.deleteCmsSiteInfoByInfoIds(infoIds);
    }

    /**
     * 删除站点信息信息
     *
     * @param infoId 站点信息主键
     * @return 结果
     */
    @Override
    public int deleteCmsSiteInfoByInfoId(Long infoId) {
        return cmsSiteInfoMapper.deleteCmsSiteInfoByInfoId(infoId);
    }
}
